package com.loong.system.controller.backend;

import com.loong.common.mvc.BaseBackendController;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonInsert;
import com.loong.common.validator.group.CommonUpdate;
import com.loong.system.common.backend.param.SystemFeedbackTypeParam;
import com.loong.system.common.backend.param.SystemFeedbackTypeQueryParam;
import com.loong.system.handler.SystemFeedbackTypeHandler;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 处理后台用户反馈类型的Controller
 */
@RestController
@RequestMapping("manage/system/feedbackType")
public class SystemFeedbackTypeController extends BaseBackendController {

    @Resource
    private SystemFeedbackTypeHandler feedbackTypeHandler;

    /**
     * 新增用户反馈类型
     * @param param 反馈类型参数
     * @return 响应的结果
     */
    @PostMapping("save")
    public Result saveFeedbackType(@Validated({CommonInsert.class})SystemFeedbackTypeParam param){
        param.setId(null);
        return handlerExecutor.execute(() -> feedbackTypeHandler.saveFeedbackType(param));
    }

    /**
     * 批量删除用户反馈类型
     * @param idList 反馈类型id集合
     * @return 响应的结果
     */
    @PostMapping("batchDelete")
    public Result batchDeleteFeedbackType(@RequestParam("idList") List<Long> idList){
        if (CollectionUtils.isEmpty(idList)) return null;
        return handlerExecutor.execute(() -> feedbackTypeHandler.batchDeleteFeedbackType(idList));
    }

    /**
     * 更新用户反馈类型
     * @param param 反馈类型参数
     * @return 响应的结果
     */
    @PostMapping("update")
    public Result updateFeedbackType(@Validated({CommonUpdate.class})SystemFeedbackTypeParam param){
        return handlerExecutor.execute(() -> feedbackTypeHandler.updateFeedbackType(param));
    }

    /**
     * 分页查询用户反馈类型
     * @param param 反馈类型参数
     * @return 响应的结果
     */
    @PostMapping("pageQuery/feedbackTypeList")
    public Result pageQueryFeedbackType(SystemFeedbackTypeQueryParam param){
        return handlerExecutor.execute(() -> feedbackTypeHandler.pageQueryFeedbackType(param));
    }

}
